package main

import (
	"fmt"
	"strconv"
)

func main2() {

	//练习转义字符
	//	fmt.Println("aaa\nbbbb")
	//\b 退格
	//fmt.Println("aaa\bbbb")
	fmt.Println("====================================")
	fmt.Println("aaaaa\rbbb")

	var s1 string = "你好第三范式"
	fmt.Println(s1)

	var s2 string = `asdfa@#$$\\\\3343\23`
	fmt.Println(s2)

	//类型转换
	var n1 int = 100
	var n2 float32 = float32(n1);
	fmt.Println(n1)
	fmt.Println(n2)
	fmt.Printf("%T\n", n1)

	var n3 int64 = 888888
	var n4 int8 = int8(n3);
	fmt.Println(n4)

	var n5 int32 = 12
	var n6 int64 = int64(n5) + 30
	fmt.Println(n6)
	var n7 int64 = 13
	var n8 int8 = int8(n7) + 127 //编译通过 但是结果可能溢出
	//var n9 int8 =int8(n7)+128 //编译不不通过
	fmt.Println(n8)
	//int类型转string
	var n11 int = 19
	var n22 float32 = 4.78
	var n33 bool = false
	var n44 byte = 'a'

	var s11 string = fmt.Sprintf("%d", n11)
	fmt.Printf("s11 对应的类型是:%T, s11=%v \n", s11, s11)

	var s22 string = fmt.Sprintf("%f", n22)
	fmt.Printf("s22 对应的类型是:%T, s22=%v \n", s22, s22)
	var s33 string = fmt.Sprintf("%t", n33)
	fmt.Printf("s33 对应的类型是:%T, s33=%v \n", s33, s33)
	var s44 string = fmt.Sprintf("%c", n44)
	fmt.Printf("s44 对应的类型是:%T, s44=%v \n", s44, s44)
	TestStringFunction()
	StringToBaseTypeFunction()
}
func TestStringFunction() {
	fmt.Println("========================================")

	var n1 int = 18
	var s1 string = strconv.FormatInt(int64(n1), 10)
	fmt.Printf("s1 对应的类型是:%T, s1=%v \n", s1, s1)

	var n2 float64 = 4.29
	var s2 string = strconv.FormatFloat(n2, 'f', -1, 64)
	fmt.Printf("s2 对应的类型是:%T, s2=%v \n", s2, s2)
}

// String 转 基本 类型
func StringToBaseTypeFunction() {
	fmt.Println("========================================")

	var s1 string = "true"
	var b bool
	b, _ = strconv.ParseBool(s1)
	fmt.Printf("对应的类型是:%T, b=%v \n", b, b)

	var s2 string = "18"
	var num1 int64
	num1, _ = strconv.ParseInt(s2, 10, 64)
	fmt.Printf("对应的类型是:%T, num1=%v \n", num1, num1)
}



